package com.headStorm.concurrent.manyThread;

/**
 * @author zhangqq
 * @create 2021-07-21 8:53
 **/
public class ThreadDemo3 {

    private final static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            synchronized (lock){
                try {
                    System.out.println("thread放弃lock锁的持有");
                    while (true){
                        System.out.println("aaa");
                        lock.wait(0);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            synchronized (lock){
                System.out.println("tread 拿到了锁");
                System.out.println("解锁");
                //lock.notify();
            }
        });
        thread.start();
        thread2.start();
        //testThreadJoinMethod();

    }


    public static void testThreadJoinMethod() throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
//                System.out.println(i);
//                try {
//                    Thread.currentThread().sleep(3 * 1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            }
        });
        System.out.println(thread.isAlive());
        thread.start();
        System.out.println(thread.isAlive());
        thread.join();
        System.out.println("aaa");
        System.out.println(thread.isAlive());
    }





}
